import { Injector } from "../injector/Injector";


/**
* 装饰class并映射Provider
* @param default_injector
* @returns
*/
export function injectable(name: string, isSingleton: boolean = true, default_injector?: Injector): Function {
    return function <T extends new (...args: any) => unknown>(target: T) {
        let injector: Injector = null;

        if (default_injector)
            injector = default_injector;
        else
            injector = Injector.default;

        if (isSingleton) {
            injector.mapSingleton(name, target);
        } else {
            injector.mapClass(name, target);
        }

        return target;
    };
}
